package com.bodu.member;

import com.bodu.core.common.AbstractCommonController;
import com.bodu.core.entity.ParamReq;
import com.bodu.core.entity.result.PageResult;
import com.bodu.core.entity.result.Result;
import com.bodu.global.security.LoginUserUtil;
import com.bodu.global.annon.TraceLog;
import com.bodu.member.entity.vo.MemberUserVo;
import com.bodu.member.entity.request.MemberUserRequest;
import com.bodu.member.service.MemberUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 成员用户表 API
* @author Administrator
*/
@Api(tags = "成员用户表 API")
@RestController
@RequestMapping("/memberUser")
public class MemberUserController extends AbstractCommonController<MemberUserService, MemberUserRequest, MemberUserVo> {

    @Autowired
    private MemberUserService memberUserService;

    @TraceLog()
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(memberUserService, id);
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("保存成员用户表")
    public Result<Integer> save(@RequestBody MemberUserRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.save(memberUserService, request);
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新成员用户表")
    public Result<Integer> update(@RequestBody MemberUserRequest request) {
        request.setCreateUser(LoginUserUtil.getUserId());
        return super.update(memberUserService, request);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("成员用户表-查询")
    public Result<List<MemberUserVo>>listPage(@RequestBody ParamReq req) {
        return super.listPage(memberUserService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("成员用户表-统计")
    public Result<Integer> countPage(@RequestBody ParamReq req) {
        return super.countPage(memberUserService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("成员用户表-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<MemberUserRequest> req) {
        return super.page(memberUserService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除成员用户表")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(memberUserService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除成员用户表")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(List<Long> ids) {
        return super.batchDelete(memberUserService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }

}
